<?php
    /*
    * @copyright        [YouNet_COPYRIGHT]
    * @author           YouNet Development
    * @package          Module_Contactimporter
    * @version          2.06
    *
    */
    defined('PHPFOX') or exit('NO DICE!');
?>
<?php
require_once (PHPFOX_DIR . 'module' . PHPFOX_DS . 'contactimporter' . PHPFOX_DS . 'include' . PHPFOX_DS . 'service' . PHPFOX_DS . 'abstract.class.php');
class Contactimporter_Service_Yahoo extends Contactimporter_Service_Abstract 
{	
    private $_provider = 'yahoo';
    
    public function get($iPage = 1, $iLimit = 50)
	{
		$iCnt = 0;
        $aErrors = $aRows = $aMails = $aInviteList = array();
        if (isset($_SESSION['contactimporter'][$this->_provider]) && $_SESSION['contactimporter'][$this->_provider])
        {                
            $aContacts = $_SESSION['contactimporter'][$this->_provider];
        }
        else
        {
            $aContacts = isset($_REQUEST['contact']) ? json_decode(urldecode($_REQUEST['contact'])) : null;
            $_SESSION['contactimporter'][$this->_provider] = $aContacts;
        }        
        $iOffset = ($iPage - 1) * $iLimit;  
        $aRows = $aMails = $aInviteList = array();
		if (!$aContacts || count($aContacts) <= 0)
		{
			return array();
		}        
		foreach ($aContacts as $i => $aContact)
		{
			$aRows[$i]['name'] = $aContact->name;
			$aRows[$i]['email'] = $aContact->email;
            $aMails[] = $aRows[$i]['email'];
		}        
        list($aMails, $aInvalid, $aJoined) = Phpfox::getService('invite')->getValid($aMails, Phpfox::getUserId());		
        $aInviteList = array();
        foreach ($aRows as $aRow)
		{
            if (in_array($aRow['email'], $aMails))
            {
                $aInviteList[] = $aRow;
            }
        }        
        $_SESSION['contactimporter'][$this->_provider . '_invite_list'] = array_values($aMails);
        $iCnt = count($aInviteList);
        $aInviteList = array_slice($aInviteList, $iOffset, $iLimit);
        $aInviteList = $this->processEmailRows($aInviteList);
        return array($iCnt, $aInviteList, $aJoined, $aErrors);
    }
}
?>